#!/usr/bin/env python
#encoding UTF-8
# edit legs.ant.king@gmail.com by 20111111
from MySQLdb import *
import time
import datetime
import xlwt
def con() :
	con = None
	try :
		con = connect( host = '' , user = '' , passwd = '' , port = 3306 , db = '' )
	except Exception , e :
		print bcolors.OKBLUE + time.strftime( '%Y-%m-%d %H:%M:%S' , time.localtime() ) + 'Can\'t Connect to Database Successful '+ str( e ) + bcolors.ENDC
	return con
def main() :
	db = con()
	cursor = db.cursor( cursorclass=cursors.DictCursor )
	for hur in xrange( 24 ) :
		sql="select bytes_received rev , bytes_sent sev from view_status_all where createtime between '20111115' and '20111116' and hour(createtime) = %s order by id asc limit 1" % hur
		sql1="select bytes_received rev , bytes_sent sev from view_status_all where createtime between '20111115' and '20111116' and hour(createtime) = %s order by id desc limit 1" % hur
		cursor.execute( sql )
		ret = cursor.fetchall()
		res1=None
		res2=None
		for i in ret :
			res1 = i['rev']
			res2 = i['sev']
			break
		cursor.execute( sql1 )
		reti = cursor.fetchall()
		res3=None
		res4=None
		for i in reti :
			res3 = i['rev']
			res4 = i['sev']
			break
		rev = res3-res1
		sev = res4-res2
		print str(hur) + ' recv ' + str(rev/1024/1024) + ' sent ' + str( sev/1024/1024 )
main()
		
